/**
 * @param {String} module_id
 */
function vgn_afterload(module_id)
{
	vgn_setdate(module_id);
	vgn_loadhistory(module_id);
	//vgn_sethistory(document.forms["efaform"+module_id],0);
	
 	_IG_AdjustIFrameHeight();
}
/**
 * @param {String} module_id
 */
function vgn_setdate(module_id)
{
	var f = document.forms["efaform"+module_id];
	var d = new Date();
	f['itdDateDay'].value = vgn_nz(2,d.getDate().toString());
	f['itdDateMonth'].value = vgn_nz(2,(d.getMonth()+1).toString());
	f['itdDateYear'].value = d.getFullYear().toString().substr(2,2);
	f['itdTimeHour'].value = vgn_nz(2,d.getHours().toString());
	f['itdTimeMinute'].value = vgn_nz(2,d.getMinutes().toString());
}
/**
 * @param (Element) el
 * @param {Number} history
 */
function vgn_sethistory(el, history)
{
	var f = vgn_parentform(el);// document.forms["efaform"+module_id];
	var h = vgnhistory.array[history];
//	f["itdTripDateTimeDepArr"].value = h.deparr; 
//	f["type_destination"].value = h.td;
	f["name_destination"].value = h.nd;
//	f["place_destination"].value = h.pd;
//	f["type_origin"].value = h.to;
	f["name_origin"].value = h.no;
//	f["place_origin"].value = h.po;
}
/**
 * @param {Form} vgn_form
 */
function vgn_onsubmit(vgn_form)
{
	try{
	var newhistory = 
	{
//		"deparr": vgn_form["itdTripDateTimeDepArr"].value,
//		"td": vgn_form["type_destination"].value,
		"nd": vgn_form["name_destination"].value,
//		"pd": vgn_form["place_destination"].value,
//		"to": vgn_form["type_origin"].value,
		"no": vgn_form["name_origin"].value,
//		"po": vgn_form["place_origin"].value
	};
	alert(1);
	vgnhistory.array[vgnhistory.array.length] = newhistory;
	//var h = vgnhistory.toJSONString();
	alert(1);
    vgnprefs.set("history", JSON.stringify(vgnhistory));
	alert(1);
	}catch(e){alert(e.message); return false;}
	return true;
}
/**
 * @param {String} module_id
 */
function vgn_loadhistory(module_id)
{
	try{
	//	alert(module_id);
    vgnprefs = new _IG_Prefs("+module_id+");
	//alert(vgnprefs);
	vgnhistory = vgnprefs.getString("history");
	//alert(vgnhistory);
    if (vgnhistory!=null && vgnhistory!="null" && vgnhistory != "" )
	{
      	vgnhistory = JSON.parse(vgnhistory);
		var historyhtml = "";
		for(i=0 , len = vgnhistory.array.length; i<len;i++)
		{
			var hel = vgnhistory.array[i];
			historyhtml += "<div><a href='javascript:;' onclick='vgn_sethistory(this,"+i+");'>"+hel.no+" - "+hel.nd+"</a></div>"
		}
		_gel("vgnhistory").innerHTML = historyhtml;
	}
	else
		vgnhistory = {"array":[]};//new Array();
	}catch(e){alert(e.message+" - "+e.name);}
}
function vgn_vorschlagen(el)
{
	var f = el.form;
	var vorschlag=(el.name=="place_destination")? f["place_origin"].value : f["place_destination"].value;
	if (el.value=="Stadt/Ort") el.value = "";
 	if (vorschlag!="Stadt/Ort" && el.value=="") 
		el.value=vorschlag;
}
function vgn_npunkt(pp)
{
	var p = pp;
	var ipcn = pp.className; 
	if (ipcn=='stop')
		p.className = 'address';
	else if (ipcn=='address')
		p.className = 'poi';
	else if (ipcn=='poi')
		p.className = 'stop';
	vgn_parentform(p)[p.id].value = p.className;
}
function vgn_nz(n,z)
{
	if (z.length == n) return z;
	else z='0'+z;
	return vgn_nz(n, z);
}
/**
 * @return {Form}
 * @param {Element} el
 */
function vgn_parentform(el)
{
	if (el!=null)
	{
		if (typeof el.tagName!='undefined' && el.tagName=='FORM') return el;
		else if (typeof el.parentNode !='undefined') return vgn_parentform(el.parentNode);
	}
	return null;
}
